package interview.se;

public class TestTransferValue {

    public static void main(String[] args) {
        int age=20;

        //String str = new String("hello");
        TestTransferValue testTransferValue = new TestTransferValue();

        testTransferValue.changeValue1(age);
        System.out.println(age);


        String str = "hello";
        testTransferValue.changeValue2(str);
        System.out.println(str);


        Person person = new Person("zhangsan",10);
        testTransferValue.changeValue3(person);
        System.out.println(person);

        Integer integer = new Integer(10);
        testTransferValue.changeValue4(integer);
        System.out.println(integer);


        String a ="a";
        String b ="a";

        String aa = new String("a");
        String bb = new String("a");
        System.out.println(a==b);    //true
        System.out.println(aa==bb);  //false
        System.out.println(a==aa);   //false
        System.out.println(b==bb);   //false
    }


    public void changeValue1(int age){
        age=22;
    }
    public void changeValue2(String str){
        str="xxx";
    }
    public void changeValue3(Person person){
        person.setName("xxxx");
    }

    public void changeValue4(Integer integer){
        integer=30;
    }


    static  class Person{

        private String name;

        private Integer age;

        public Person(String name, Integer age) {
            this.name = name;
            this.age = age;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getAge() {
            return age;
        }

        public void setAge(Integer age) {
            this.age = age;
        }

        @Override
        public String toString() {
            return "Person{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    '}';
        }
    }
}
